/*
 * ScreenData.java
 * Created on August 10, 2008, 6:25 PM by Uru
 *
 * Contains data on a screen when it is not in the stack
 * allows the easy creation of menus from their names
 */

package ScreenSystem;

//this should be the only place in the entire base system that imports specific screen subclasses
import MenuSystem.GameMenu;
import AnimationSystem.AnimMenu;

public class ScreenData {
    private String name;
    private String filename;
    private Screen screen;
    
    //Creates a new instance of ScreenData using a filename
    public ScreenData(String n, String f){
        name = n;
        filename = f;
        screen = null;
    }
    
    //Creates a new instance of ScreenData using a screen
    public ScreenData(String n, Screen s){
        name = n;
        filename = null;
        screen = s;
    }
    
    public Screen loadScreen(){
        if(screen != null){
            return screen;
        }else{
            return loadFromFilename();
        }
    }
    
    //a constructor wrapper that allows new screens to be created easily from files
    //Uses file extension to determine type
    //NEW SCREEN TYPES MUST BE ADDED HERE
    private Screen loadFromFilename(){
        //Menu?
        if((filename.substring(filename.length()-5)).toLowerCase().equals(".menu")){
            System.out.println("Loading Menu");
            return new GameMenu(filename);
        }
        else if((filename.substring(filename.length()-5)).toLowerCase().equals(".anim")){
            System.out.println("Loading Animation");
            return new AnimMenu(filename);
        }
        //could not determine file type
        return null;
    }
    
}
